<?php


namespace App\Admin\Controllers;


use App\Admin\Controller\AdminBaseController;
use App\Admin\Services\UploadImgService;

class UploadImgController extends AdminBaseController {
    public $exceptActionList = ['storeImgToAliOss'];
    protected $_service;
    
    public function __construct(UploadImgService $service) {
        $this->_service = $service;
    }
    
    /**
     * 图片上传接口
     * @return mixed
     * @throws \App\Commons\Exceptions\AliyunCsException
     * @throws \OSS\Core\OssException
     */
    public function storeImgToAliOss() {
        if (env('APP_ENV') === 'local') {
            return $this->success([
                request()->input('imgUrlProName') ?: 'fileUrl' => '/favicon.ico',
                'fileName'                                     => '838b3309c4927c08a95d679c993c6e42.png',
                'isMockPic'                                    => true,
            ]);
        }

        $uploadResult = UploadImgService::storeImgToAliOss();
        $imgUrlPro    = request()->input('imgUrlProName') ?: 'fileUrl';
        
        return $this->success([
            $imgUrlPro => $uploadResult['fileUrl'],
            'fileName' => $uploadResult['fileName'],
        ]);
    }
}